home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / cview.jar / content / cview / cview-handlers.js < prev    next >
Encoding:
JavaScript  |  2004-04-18  |  6.5 KB  |  228 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is mozilla.org code.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1998
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *   Robert Ginda, rginda@netscape.com, original author
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. /*
  41.  * This file contains event handlers for cview.  The main code of cview is
  42.  * divided between this file and cview-static.js
  43.  */
  44.  
  45. function onLoad()
  46. {
  47.     initTrees();
  48.     cview.totalComponents = cview.visibleComponents = 
  49.         cview.componentView.rowCount;
  50.     cview.totalInterfaces = cview.visibleInterfaces = 
  51.         cview.interfaceView.rowCount;
  52.     refreshLabels();
  53. }
  54.  
  55. function onUnload()
  56. {
  57.     /* nothing important to do onUnload yet */
  58. }
  59.  
  60. function onComponentClick(e)
  61. {
  62.     if (e.originalTarget.localName == "treecol")
  63.     {
  64.         onTreeResort(e, cview.componentView);
  65.     }
  66.     else
  67.     {
  68.         /*
  69.         cview.lastContractID = e.target.parentNode.getAttribute("contractid");
  70.     
  71.         if (cview.interfaceMode == "implemented-by")
  72.         {
  73.             cview.interfaceFilter = cview.lastContractID;
  74.             filterInterfaces();
  75.         }
  76.         */
  77.     }
  78. }
  79.  
  80. function onInterfaceClick(e)
  81. {
  82.     if (e.originalTarget.localName == "treecol")
  83.     {
  84.         onTreeResort(e, cview.interfaceView);
  85.     }
  86.     else
  87.     {
  88.         /*
  89.         cview.lastIID = e.target.parentNode.getAttribute("iid");
  90.         refreshLabels();
  91.         */
  92.     }
  93. }
  94.  
  95. function onTreeResort (e, view)
  96. {
  97.     /* resort by column */
  98.     var rowIndex = new Object();
  99.     var col = new Object();
  100.     var childElt = new Object();
  101.     
  102.     var obo = view.tree;
  103.     obo.getCellAt(e.clientX, e.clientY, rowIndex, col, childElt);
  104.     if (rowIndex.value == -1)
  105.       return;
  106.  
  107.     var prop;
  108.     switch (col.value.id.substr(4))
  109.     {
  110.         case "name":
  111.             prop = "sortName";
  112.             break;
  113.         case "number":
  114.             prop = "sortNumber";
  115.             break;
  116.     }
  117.     
  118.     var root = view.childData;
  119.     var dir = (prop == root._share.sortColumn) ?
  120.         root._share.sortDirection * -1 : 1;
  121.     root.setSortColumn (prop, dir);
  122. }
  123.  
  124. function onComponentSelect (e)
  125. {
  126.     var index = cview.componentView.selection.currentIndex;
  127.     var row = cview.componentView.childData.locateChildByVisualRow (index);
  128.     if (!row)
  129.         return;
  130.  
  131.     var text = document.getElementById ("output-text");
  132.     text.value = row.getText();
  133. }
  134.  
  135. function onInterfaceSelect (e)
  136. {
  137.     var index = cview.interfaceView.selection.currentIndex;
  138.     var row = cview.interfaceView.childData.locateChildByVisualRow (index);
  139.     if (!row)
  140.         return;
  141.  
  142.     var text = document.getElementById ("output-text");
  143.     text.value = row.getText();
  144. }
  145.             
  146. function onLXRIFCLookup (e, type)
  147. {
  148.     var index = cview.interfaceView.selection.currentIndex;
  149.     var row = cview.interfaceView.childData.locateChildByVisualRow (index);
  150.     if (!row)
  151.         return;
  152.     
  153.     /* Specifing "_content" as the second parameter to window.open places
  154.      * the url in the most recently open browser window
  155.      */
  156.     window.open ("http://lxr.mozilla.org/mozilla/" + type + row.name,
  157.                  "_content", "");
  158. }
  159.  
  160. function onChangeDisplayMode (e)
  161. {
  162.     var id = e.target.getAttribute("id");
  163.     var ary = id.match (/menu-(cmp|ifc)-show-(.*)/);
  164.     if (!ary)
  165.     {
  166.         dd ("** UNKNOWN ID '" + id + "' in onChangeDisplayMode **");
  167.         return;
  168.     }
  169.     
  170.     var typeDesc;
  171.         var el;
  172.     if (ary[1] == "cmp") {
  173.         typeDesc = "Components";
  174.         el = document.getElementById("menu-cmp-show-all");
  175.         el.setAttribute("checked", false);
  176.         el = document.getElementById("menu-cmp-show-contains");
  177.         el.setAttribute("checked", false);
  178.         el = document.getElementById("menu-cmp-show-starts-with");
  179.         el.setAttribute("checked", false);
  180.     } else {
  181.         typeDesc = "Interfaces";
  182.         el = document.getElementById("menu-ifc-show-all");
  183.         el.setAttribute("checked", false);
  184.         el = document.getElementById("menu-ifc-show-contains");
  185.         el.setAttribute("checked", false);
  186.         el = document.getElementById("menu-ifc-show-starts-with");
  187.         el.setAttribute("checked", false);
  188.         el = document.getElementById("menu-ifc-show-implemented-by");
  189.         el.setAttribute("checked", false);
  190.     }
  191.     
  192.     e.target.setAttribute ("checked", true);
  193.     var filter = "";
  194.  
  195.     if (ary[2] == "contains")
  196.     {
  197.         filter = window.prompt ("Show only " + typeDesc + " containing...");
  198.         if (!filter)
  199.             return;
  200.         filter = new RegExp(filter, "i");    
  201.     }
  202.     
  203.     if (ary[2] == "starts-with")
  204.     {
  205.         filter = window.prompt ("Show only " + typeDesc + " starting with...");
  206.         if (!filter)
  207.             return;
  208.         filter = new RegExp(filter, "i");    
  209.     }
  210.  
  211.     if (ary[2] == "implemented-by")
  212.         filter = cview.lastContractID;
  213.  
  214.     if (ary[1] == "cmp")
  215.     {
  216.         cview.componentMode = ary[2];
  217.         cview.componentFilter = filter;
  218.         filterComponents();
  219.     }
  220.     else
  221.     {
  222.         cview.interfaceMode = ary[2];
  223.         cview.interfaceFilter = filter;
  224.         filterInterfaces();
  225.     }
  226.     
  227. }
  228.